package com.dingding.core.tailwind.service.impl;

import javax.annotation.Resource;

import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;

import com.dingding.common.core.base.dto.ResponseEntity;
import com.dingding.common.core.beans.UserLogin;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.core.tailwind.dao.IDepositPasswordDao;
import com.dingding.core.tailwind.service.IDepositPasswordService;
import com.dingding.facade.user.common.dto.tailwind.ReqForgetDepositPassword;
import com.dingding.facade.user.common.dto.tailwind.ReqUpdateDepositPassword;

/**
 * 
 * @ClassName: DepositPasswordServiceImpl 
 * @Description: 提现密码业务逻辑实现类
 * @author YHQ
 * @date 2016年12月22日 上午10:18:19
 * @since V2.6.3
 * 
 */
@Component("depositPasswordService")
public class DepositPasswordServiceImpl implements IDepositPasswordService{

	@Resource(name = "depositPasswordDao")
	private IDepositPasswordDao depositPasswordDao;
	
	/**
	 * 
	 * @Title: updateUserDepositPassword 
	 * @Description: 修改用户提现密码(乘客端)
	 * @param reqUpdateDepositPassword 修改用户提现密码客户端请求Bean
	 * @author YHQ 
	 * @return ResponseEntity<Object>
	 * 
	 */
	@Override
	public ResponseEntity<Object> updateUserDepositPassword(ReqUpdateDepositPassword reqUpdateDepositPassword) {
		
		ResponseEntity<Object> responseEntity = new ResponseEntity<Object>();
		
		// 判断客户端请求参数是否为空
		if(reqUpdateDepositPassword == null || !ToolUtil.validateParam(reqUpdateDepositPassword)){
			
			responseEntity.setCode(HttpStatus.SC_BAD_REQUEST);
			responseEntity.setErrorMessage("客户端请求数据为空");
			responseEntity.setPromptMessage("请求数据异常");
			
			return responseEntity;
		}
		
		// 根据用户Id获取用户登录信息
		UserLogin userLogin = depositPasswordDao.getUserLogin(reqUpdateDepositPassword.getUserId());
		
		if(userLogin != null && ToolUtil.isNotBlank(userLogin.getDepositPwd())){
			
			if(userLogin.getDepositPwd().equals(reqUpdateDepositPassword.getUsedPassword())){
				
				boolean flag = depositPasswordDao.updateUserDepositPassword(reqUpdateDepositPassword.getUserId(), reqUpdateDepositPassword.getNewPassword());
				
				if(flag){
					responseEntity.setCode(HttpStatus.SC_OK);
				}else{
					responseEntity.setCode(HttpStatus.SC_BAD_REQUEST);
					responseEntity.setErrorMessage("修改密码失败");
					responseEntity.setPromptMessage("修改密码失败");
				}
				
				return responseEntity;
			}else{
				responseEntity.setCode(HttpStatus.SC_BAD_REQUEST);
				responseEntity.setErrorMessage("原密码输入有误");
				responseEntity.setPromptMessage("原密码输入有误");
			}
			
		}else{
			responseEntity.setCode(HttpStatus.SC_BAD_REQUEST);
			responseEntity.setErrorMessage("该用户不存在或者提现密码未设置");
			responseEntity.setPromptMessage("该用户不存在或者提现密码未设置");
		}
		
		return responseEntity;
	}

	/**
	 * 
	 * @Title: forgetDepositPassword 
	 * @Description: 忘记提现密码(乘客端) 
	 * @param reqForgetDepositPassword 忘记提现密码客户端请求Bean
	 * @author YHQ 
	 * @since V2.6.3
	 * @return ResponseEntity<Object>    返回类型
	 * 
	 */
	@Override
	public ResponseEntity<Object> forgetDepositPassword(ReqForgetDepositPassword reqForgetDepositPassword) {
		
		ResponseEntity<Object> responseEntity = new ResponseEntity<>();
		
		// 判断客户端请求参数是否为空
		if(reqForgetDepositPassword == null || !ToolUtil.validateParam(reqForgetDepositPassword)){
			
			responseEntity.setCode(HttpStatus.SC_BAD_REQUEST);
			responseEntity.setErrorMessage("客户端请求数据为空");
			responseEntity.setPromptMessage("请求数据异常");
			
			return responseEntity;
		}
		
		// 忘记提现密码(乘客端)  true:成功   false:失败
		boolean flag = depositPasswordDao.updateUserDepositPassword(reqForgetDepositPassword.getUserId(), reqForgetDepositPassword.getNewPassword());
		
		if(flag){
			responseEntity.setCode(HttpStatus.SC_OK);
		}else{
			responseEntity.setCode(HttpStatus.SC_BAD_REQUEST);
			responseEntity.setErrorMessage("忘记提现密码修改失败");
			responseEntity.setPromptMessage("忘记提现密码修改失败");
		}
		
		return responseEntity;
	}

}
